<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";

import { tableSqls } from "./sql/tableSql";

import { openSqlite, createTable, isOpen, deleteSql } from "./util/sqlUtils";
import { BASE_IP } from "./util/Constants";
import { base_ip } from "./util/request";
import { useStore } from "vuex";
import { getUserInfo } from "./api/user";
import { loginService } from "./pagesVM/login";

const store = useStore()

onLaunch(() => {
  uni.getStorage({
    key: BASE_IP,
    success: (res) => {
      base_ip.value = res.data
    },
    fail: () => {
      //服务器IP配置 如果是Android 模拟器的化 需要填写 外层物理机IP地址
      base_ip.value = '192.168.0.153'
    }
  })

  if (!isOpen()) {
    openSqlite().then(e => {
      //('数据库链接成功')
      console.log("openSqlite success")
      createTable(tableSqls)
    })
  }
});
onShow(async () => {
  //("App Show");
  await createTable(tableSqls)
});
onHide(() => {
  //("App Hide");
});

const { onlineLogin } = loginService()

const checkToken = () => {
  uni.getStorage({
    key: 'token',
    success: (res) => {
      store.dispatch('SET_TOKEN', res.data)
    }
  })
}
</script>
<style></style>
